//
//  CXPowerButton.swift
//  xingluoluo
//
//  Created by Mac Book on 2018/12/27.
//  Copyright © 2018 李旭峰. All rights reserved.
//

import UIKit

class CXPowerButton: CXIconButton {
    private var padding = UIEdgeInsets.zero
    @IBInspectable var paddingLeft:CGFloat {
        get { return padding.left }
        set { padding.left = newValue }
    }
    @IBInspectable var paddingRight:CGFloat {
        get { return padding.right }
        set { padding.right = newValue }
    }
    @IBInspectable var paddingTop:CGFloat {
        get { return padding.top }
        set { padding.top = newValue }
    }
    @IBInspectable var paddingBottom:CGFloat {
        get { return padding.bottom }
        set { padding.bottom = newValue }
    }
    @IBInspectable var paddingValue:UIEdgeInsets {
        get{ return padding }
        set{ padding = newValue }
    }
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        let tempOffsetLeft = max(0.0, self.padding.left)
        let tempOffsetRight = max(0.0, self.padding.right)
        let tempOffsetTop = max(0.0, self.padding.top)
        let tempOffsetBottom = max(0.0, self.padding.bottom)
        let szPointX : CGFloat = -1.0 * tempOffsetLeft
        let szPointY : CGFloat = -1.0 * tempOffsetTop
        let szWidth : CGFloat = self.bounds.size.width + tempOffsetLeft + tempOffsetRight
        let szHeight : CGFloat = self.bounds.size.height + tempOffsetTop + tempOffsetBottom
        let area = CGRect(x: szPointX, y: szPointY, width: szWidth, height: szHeight)
        return area.contains(point)
    }
}
